# -*- coding: utf-8 -*-
# @author: 龙非池
from __future__ import unicode_literals

from django.db import models

from wlmodels.codes.dicts import cd14_dict, cb16_dict, cb17_dict, ce03_dict, ce08_dict, ce16_dict, ce19_dict, ce22_dict, ce36_dict, ce37_dict, \
    ce38_dict, ce39_dict
from wlmodels.codes.fields import CrossForeignCharField
from wlmodels.codes.models import ELBaseModel, ELRegion, ELCA11, ELCE02, ELCE10, EntIdable


# 清算信息
class ELLiqentidation(ELBaseModel):
    entobj = models.ForeignKey('company.ELPost', verbose_name='所属企业', db_column='entid', default=0,
                               related_name='c_liquidation', to_field='entid')
    LIGENTITY = models.CharField('清算责任人', max_length=100, null=True, blank=True)
    LIGPRINCIPAL = models.CharField('清算负责人', max_length=100, null=True, blank=True)
    LIQMEN = models.TextField('清算组成员', null=True, blank=True)
    ADDR = models.CharField('地址', max_length=128, null=True, blank=True)
    TEL = models.CharField('联系电话', max_length=30, null=True, blank=True)
    LIGST = models.CharField('清算完结情况', max_length=2, null=True, blank=True, choices=cd14_dict)
    LIGENDDATE = models.DateField('清算完结日期', null=True, blank=True)
    DEBTTRANEE = models.TextField('债务承接人', null=True, blank=True)
    CLAIMTRANEE = models.TextField('债权承接人', null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '企业清算信息'
        verbose_name_plural = '企业清算信息'
        app_label = "company"
        db_table = 'company_liquidation'

    def _entid(self):
        from wlmodels.company.models import ELPost
        entid = ELPost.objects.filter(entid=self.entobj_id).first()
        if entid:
            return entid
        return ""

    _entid.short_description = "所属企业"

    entid = property(_entid)

    def __unicode__(self):
        return u'%s的清算信息' % self.entid


# 工商行政处罚主体信息
class ELCaseBasic(ELBaseModel):
    entobj = models.ForeignKey('company.ELPost', verbose_name='所属企业', db_column='entid', default=0,
                               related_name='case_basic', to_field='entid')
    personid = models.ForeignKey('company.ELPerson', verbose_name='关联个人', db_column='personid', null=True, blank=True,
                                 related_name='p_case_person', to_field='personid', default=0)
    caseid = models.IntegerField('案件id', default=0, blank=True)
    NAME = models.CharField('当事人名称', max_length=100, null=True, blank=True)
    PARTYTYPE = models.CharField('当事人类型', max_length=1, null=True, blank=True, choices=(('0', '自然人'), ('1', '法人或其他组织'),))
    REGNO = models.CharField('工商注册号', max_length=30, null=True, blank=True, db_index=True)
    LEREP = models.CharField('法人', max_length=100, null=True, blank=True)
    CERNO = models.CharField('证件号码', max_length=30, null=True, blank=True, db_index=True)
    CERTYPE = models.CharField('证件类型', max_length=2, null=True, blank=True, choices=cb16_dict)
    P_ID = models.CharField('人员ID', max_length=50, null=True, blank=True, help_text='处罚序号,非标准指标')
    PRIPID = models.CharField('中数企业UID', max_length=36, null=True, blank=True)
    SEX = models.CharField('性别', max_length=1, null=True, blank=True, choices=cb17_dict)
    ADDR = models.CharField('地址', max_length=100, null=True, blank=True)
    AGE = models.IntegerField('年龄', null=True, blank=True)
    OCCUPATION = models.CharField('职业', max_length=100, null=True, blank=True)
    HOUSE = models.CharField('居所', max_length=100, null=True, blank=True)
    TEL = models.CharField('联系电话', max_length=30, null=True, blank=True)
    POSTALCODE = models.CharField('邮编', max_length=6, null=True, blank=True)
    WORKUNIT = models.CharField('工作单位', max_length=100, null=True, blank=True)
    TERCORDATE = models.DateField('限期改正日期', null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '行政处罚主体'
        verbose_name_plural = '行政处罚主体'
        app_label = "company"
        db_table = 'case_basic'

    def _entid(self):
        from wlmodels.company.models import ELPost
        entid = ELPost.objects.filter(entid=self.entobj_id).first()
        if entid:
            return entid
        return ""

    _entid.short_description = "所属企业"

    entid = property(_entid)

    def __unicode__(self):
        if self.entid:
            return u'%s的案件主体信息' % self.entid
        return "行政处罚主体-%s" % self.id


# 工商行政处罚案件详情
class ELCaseDetail(ELBaseModel):
    caseid = models.IntegerField('案件id', default=0, blank=True)
    CASENO = models.CharField('案件编号', max_length=50, null=True, blank=True)
    CASENAME = models.CharField('案件名称', max_length=100, null=True, blank=True)
    CASETIME = models.DateTimeField('案发时间', null=True, blank=True)
    CASESPOT = models.TextField('案发地', null=True, blank=True)
    CASESCEDISTRICT_id = CrossForeignCharField('行政区划', db_column='CASESCEDISTRICT', max_length=6, null=True, blank=True)
    CASEREASON = models.TextField('案由', null=True, blank=True)
    CASEVAL = models.FloatField('案值', null=True, blank=True)
    CASERESULT = models.CharField('案件结果', max_length=2, null=True, blank=True, choices=ce36_dict)
    CASETYPE = models.CharField('案件类型', max_length=2, null=True, blank=True, choices=ce37_dict)
    APPPROCEDURE = models.CharField('适用程序', max_length=2, null=True, blank=True, choices=ce08_dict)
    CASEFIDATE = models.DateField('立案日期', null=True, blank=True)
    CASEFIAUTH = models.CharField('立案机关', max_length=100, null=True, blank=True)
    CASEDEP = models.CharField('办案机构', max_length=100, null=True, blank=True)
    EXEDATE = models.DateField('执行日期', null=True, blank=True)
    EXESORT = models.CharField('执行类别', max_length=2, null=True, blank=True, choices=ce38_dict)
    UNEXEREASORT = models.CharField('未执行原因类别', max_length=1, null=True, blank=True, choices=ce39_dict)
    UNEXEREA = models.TextField('未执行原因', null=True, blank=True)
    CLOCASEDATE = models.DateField('销案日期', null=True, blank=True)
    CLOCASEREA = models.CharField('销案理由', max_length=1, null=True, blank=True, choices=ce19_dict)
    SUPAUTH = models.CharField('上报机关', max_length=100, null=True, blank=True)
    REPODATE = models.DateField('报送日期', null=True, blank=True)
    ENDCASDATE = models.DateField('案件结束日期', null=True, blank=True)
    CASESTATE = models.CharField('案件状态', max_length=1, null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '行政处罚案件'
        verbose_name_plural = '行政处罚案件'
        app_label = "company"
        db_table = 'case_detail'

    def __unicode__(self):
        return u'行政处罚案件-%s' % self.id

    def _casescedistrict(self):
        return ELRegion.get_region(self.CASESCEDISTRICT_id)

    _casescedistrict.short_description = "行政区划"

    CASESCEDISTRICT = property(_casescedistrict)


# 行政处罚处罚信息
class ELCasePunish(ELBaseModel):
    caseid = models.IntegerField('案件id', default=0, blank=True)
    ILLEGACT_ID = models.CharField('处罚序号', max_length=50, null=True, blank=True)
    ILLEGACTTYPE_id = CrossForeignCharField('违法行为种类', db_column='ILLEGACTTYPE', max_length=6, null=True, blank=True)
    ILLEGACT = models.TextField('违法行为', null=True, blank=True)
    ILLACTFINDAVE = models.CharField('违法行为发现途径', max_length=2, null=True, blank=True, choices=ce03_dict)
    ILLINCOME = models.FloatField('违法所得', null=True, blank=True, help_text='单位：万元')
    QUAGIST_id = CrossForeignCharField('定性依据', db_column='QUAGIST', max_length=6, null=True, blank=True)
    PENBASIS_id = CrossForeignCharField('处罚依据', db_column='PENBASIS', max_length=6, null=True, blank=True)
    PENTYPE = models.CharField('处罚种类', max_length=2, null=True, blank=True, choices=ce16_dict)
    PENRESULT = models.CharField('处罚结果', max_length=2, null=True, blank=True, choices=ce22_dict)
    PENAM = models.FloatField('处罚金额', null=True, blank=True, help_text='单位：万元')
    FORFAM = models.FloatField('没收金额', null=True, blank=True, help_text='单位：万元')
    APPRCURAM = models.FloatField('变价金额', null=True, blank=True, help_text='单位：万元')
    PENDECISSDATE = models.DateField('处罚决定书签发日期', null=True, blank=True)
    PENEXEST = models.TextField('处罚执行情况', null=True, blank=True)
    PENAUTH_id = CrossForeignCharField('处罚机关', db_column='PENAUTH', max_length=8, null=True, blank=True)
    PENDECNO = models.CharField('处罚决定书文号', max_length=50, null=True, blank=True)
    ILLEGFACT = models.TextField('主要违法事实', null=True, blank=True)
    REVST = models.TextField('复议情况', null=True, blank=True)
    LIT = models.TextField('诉讼情况', null=True, blank=True)
    TOJUDST = models.TextField('移送司法机关情况', null=True, blank=True)
    ISCAN = models.CharField('是否注销', max_length=1, null=True, blank=True, choices=(('1', '是'), ('2', '否')))
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '行政处罚处罚信息'
        verbose_name_plural = '行政处罚处罚信息'
        app_label = "company"
        db_table = 'case_punish'

    def __unicode__(self):
        return u'行政处罚处罚信息-%s' % self.id

    def _illegacttype(self):
        the_illegacttype = list(ELCE02.objects.filter(code=self.ILLEGACTTYPE_id).values_list("name", flat=True))
        if len(the_illegacttype):
            return the_illegacttype[0]
        return ""

    _illegacttype.short_description = "违法行为种类"

    ILLEGACTTYPE = property(_illegacttype)

    def _quagist(self):
        the_quagist = list(ELCE10.objects.filter(code=self.QUAGIST_id).values_list("name", flat=True))
        if len(the_quagist):
            return the_quagist[0]
        return ""

    _quagist.short_description = "定性依据"

    QUAGIST = property(_quagist)

    def _penbasis(self):
        the_penbasis = list(ELCE10.objects.filter(code=self.PENBASIS_id).values_list("name", flat=True))
        if len(the_penbasis):
            return the_penbasis[0]
        return ""

    _penbasis.short_description = "处罚依据"

    PENBASIS = property(_penbasis)

    def _penauth(self):
        the_penauth = list(ELCA11.objects.filter(code=self.PENAUTH_id).values_list("name", flat=True))
        if len(the_penauth):
            return the_penauth[0]
        return ""

    _penauth.short_description = "处罚机关"

    PENAUTH = property(_penauth)


# 案源信息
class ELCaseSrc(ELBaseModel):
    caseid = models.IntegerField('案件id', default=0, blank=True)
    CASESRC_ID = models.CharField('案源ID', max_length=50, null=True, blank=True)
    CASESOU = models.CharField('案件来源', max_length=4, null=True, blank=True, choices=ce03_dict)
    CLUECON = models.TextField('线索(举报)内容', null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '行政处罚案源信息'
        verbose_name_plural = '行政处罚案源信息'
        app_label = "companyplus"
        db_table = 'case_src'

    def __unicode__(self):
        return u'行政处罚案源信息-%s' % self.id


# 被判刑或剥夺政治权利的信息
class ELCaseIllegal(EntIdable):
    personid = models.IntegerField('关联个人id', default=0, blank=True)
    JUD_ID = models.CharField('判决ID', max_length=50, null=True, blank=True)
    EXETO = models.DateField('执行截止日期', null=True, blank=True)
    JUDAUTH = models.TextField('判决机关', null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '被判刑或剥夺政治权利的信息'
        verbose_name_plural = '被判刑或剥夺政治权利的信息'
        app_label = "companyplus"
        db_table = 'case_illegal'

    def __unicode__(self):
        return u'被判刑或剥夺政治权利的信息-%s' % self.id


# 被通缉信息
class ELCaseWanted(EntIdable):
    personid = models.IntegerField('关联个人id', default=0, blank=True)
    WANT_ID = models.CharField('通缉ID', max_length=50, null=True, blank=True)
    WANTAUTH = models.CharField('通缉机关', max_length=100, null=True, blank=True)
    updated = models.DateTimeField('更新时间', null=True, blank=True)

    class Meta:
        verbose_name = '被通缉信息'
        verbose_name_plural = '被通缉信息'
        app_label = "companyplus"
        db_table = 'case_wanted'

    def __unicode__(self):
        return u'被通缉信息-%s' % self.id


# 案件id映射
class ELCaseinfoid(ELBaseModel):
    caseid = models.IntegerField('案件id', db_column='caseid', primary_key=True)
    CASEINFOID = models.CharField('案件记录id', max_length=100, null=True, db_index=True)

    class Meta:
        verbose_name = '案件id映射'
        verbose_name_plural = '案件id映射'
        app_label = "companyplus"
        db_table = 'company_id_case_caseinfoid'

    def __unicode__(self):
        return u'案件id映射-%s' % self.caseid


models_law_imported = 0  # 仅供主model引用的虚变量
